<?php
namespace Home\Controller;
use Think\Controller;
class LinkController extends XmlController {

    public function edit(){
    	
    	$link_id = $_POST['link_id'];
    	$link = D("link");
    	if(!$link->create()){
    		$array = array('success'=>0, 'error'=>$link->getError());
    		exit(json_encode($array));
    	}else{
    		$res = $link->where("link_id='%d'", $link_id)->save();
	        if($res!==false){
                $this->newXml();
	            echo '{"success":1}';
	        }else{
	            echo '{"success":0,"error":"修改失败."}';
	        }
    	}
    }

    public function add(){
        $link = D('link');
        if(!$link->create()){
            $array = array('success'=>0, 'error'=>$link->getError());
            exit(json_encode($array));
        }else{
            $res = $link->add();
            if($res!==false){
                $this->newXml();
                echo '{"success":1}';
            }else{
                echo '{"success":0,"error":"添加失败."}';
            }
        }
    }

    public function del(){
        $db_link = M('link');
        $link_id = I('link_id');
        $res = $db_link->where("link_id = '%d'", $link_id)->delete();
        if($res!==false){
            $this->newXml();
            echo '{"success":1}';
        }else{
            echo '{"success":0,"error":"删除失败."}';
        }
    }
}